package com.study.www.web;

import com.alibaba.fastjson.JSON;
import com.study.www.config.IdWorks;
import com.study.www.config.MapperCannerConfigurer;
import com.study.www.test1.dao.DeptMapper;
import com.study.www.test1.entity.Dept;
import com.study.www.test2.dao.LoggerMapper;
import com.study.www.test2.entity.Logger;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 部门
 *
 * @author : 89007337.zhuyanpeng
 * @date :Create in  2019/8/23- 19:16
 **/
@RestController
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    DeptMapper deptMapper;
    @Autowired
    LoggerMapper loggerMapper;


    @GetMapping("")
    public String get(){
        List<Dept> depts = deptMapper.queryList();
        return JSON.toJSONString(depts);
    }
//(transactionManager = MapperCannerConfigurer.TEST2TRANSACTIONMANAGER)
    @PostMapping("")
    @Transactional
    public String post(@RequestBody Dept dept){
        dept.setId(IdWorks.getId());
        dept.setCreateTime(new Date());
        deptMapper.insert(dept);
        Logger logger = new Logger();
        logger.setId(IdWorks.getId());
        logger.setUrl("test");
        logger.setDescription("测试2");
        logger.setHttpMethod("GET");
        logger.setClassName("classTest");
        logger.setIpAddress("127.0.0.1");
        logger.setTime(1200L);
        logger.setCreateTime(new Date());
        loggerMapper.insert(logger);
        return "OK";
    }

}
